package com.leyou.item.dto;

import com.leyou.commons.dto.BaseDTO;
import com.leyou.commons.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class BrandDTO extends BaseDTO {
    private long id;
    private String name;
    private String image;
    private Character letter;
    private List<Long> categoryIds;
    //调用父类的方法执行值传递
    public BrandDTO(BaseEntity entity){
    super(entity);
    }

    /**
     * 遍历传递过来的品牌集合
     * 并把brand集合转换成brandDTO集合返回
     * @param list
     * @param <T>
     * @return
     */
    public static <T extends BaseEntity> List<BrandDTO> convertEntityList(Collection<T> list){
        if (CollectionUtils.isEmpty(list)){
            return Collections.emptyList();
        }
       return list.stream().map(BrandDTO::new).collect(Collectors.toList());
    }
}
